package com.heima;

import java.util.Scanner;
import java.util.SortedMap;

public class sz1 {
    public static void main(String[] args) {

        //-----两个数组指向
      /*  int[] arr = new int[3];
        System.out.println(arr);
        arr[0] = 11;
        arr[1] = 33;
        arr[2] = 66;
        System.out.println(arr[0]);
        System.out.println(arr[1]);
        System.out.println(arr[2]);
        System.out.println("/////");
        int brr[]=arr;
        System.out.println(brr);
        arr[0]=99;
        System.out.println(arr[0]);
        System.out.println(arr[1]);
        System.out.println(arr[2]); */


        //-------找出最大值
         /* int[] arr = {6, 4, 2, 8, 7};
        int mini = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < mini) {
                mini = arr[i];
            }
        }
        System.out.println("最大值是"+mini); */


        //-----在50-100的范围内键盘输入五个数求和
  /* //创建对象
  Scanner sc = new Scanner(System.in);
       //定义变量和
        int sum = 0;
        //定义一个数组长度为5
        int[] arr = new int[5];
        //for循环查找每个数
        for (int i = 0; i < arr.length; i++) {
            //打印输入的数值
            System.out.println("请输入第" + (i + 1) + "个整数");
            //定义变量num赋给键盘录入
            int num = sc.nextInt();
            //if语句判断数值范围为50和100以内
            if (num>=50&&num<=100){
                //数组值给num
                arr[i] = num;
            //否则
            }else{
                System.out.println("输入错误");
                i--;//回退for循环
            }
        }
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("sum" + sum);    */


        /* 计算键盘录入多个数值的和
            创建对象
            定义变量和
            定义数组值为3
            for循环查找每个数
            打印数值
            键盘录入输出给num
            数组i等于sum
            for循环再次查找每个数
            数组中输入的数值求和给sum
            打印出和
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        int[] arr = new int[3];
        for (int i = 0; i < arr.length; i++) {
            System.out.println("第" + (i + 1) + "个");
            int num = sc.nextInt();
            arr[i] = num;
        }

        for (int i=0;i<arr.length;i++){
                sum+=arr[i];
            }
        System.out.println("sum="+sum);     */

        int[] arr = {19, 28, 37, 46, 50};
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要查找的数据： ");
            int num = sc.nextInt();
            int sy = -1;
            for (int i = 0; i < arr.length; i++) {
                if (num == arr[i]) {
                    sy = i;
                    break;
                }
            }
            System.out.println("索引: " + sy);
        }
        

    }
}
